﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AuditModel;

namespace TestAuditModel
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                IAnnualEventBL ibl = new AnnualEventBL();
                GridView1.DataSource = ibl.GetActiveEvents();
                GridView1.DataBind();

                AuditDBEntities db = new AuditDBEntities();

                drpAnnualEvent.DataSource = from t in db.AnnualEvents
                                            select t.ID;
                drpAnnualEvent.DataBind();

                drpSubject.DataSource = from t in db.Subjects
                                        select t.Id;
                drpSubject.DataBind();

                drpCounty.DataSource = from t in db.Counties
                                       select t.Code;
                drpCounty.DataBind();

                drpArchives.DataSource = from t in db.Archives
                                         select t.ID;
                drpArchives.DataBind();

                drpExperts.DataSource = from t in db.ExpertJudges
                             select t.SerialNumber;
                drpExperts.DataBind();
            }
            //ibl.GetAnnualEvent("").CandidateQuotas.Single();

        }

        protected void btnCandidateQuota_Click(object sender, EventArgs e)
        {
            ICandidateQuotaBL ibl = new CandidateQuotaBL();
            GridView1.DataSource=ibl.GetCandidateQuotas(drpAnnualEvent.Text, Convert.ToInt32(drpSubject.Text),
                drpCounty.Text);
            GridView1.DataBind();
        }

        protected void btnArchives_Click(object sender, EventArgs e)
        {
            IArchiveBL ibl = new ArchiveBL();
            GridView1.DataSource = ibl.GetArchives(drpAnnualEvent.Text, "", 0, "");
            GridView1.DataBind();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            IArchiveBL ibl = new ArchiveBL();
            Archive a=new Archive();
            a.AnnualEventID=drpAnnualEvent.Text;
            a.CountyCode=drpCounty.Text;
            a.SubjectID=Convert.ToInt32(drpSubject.Text);
            ibl.Add(a);

            AuditDBEntities db=new AuditDBEntities();
            GridView1.DataSource = db.Archives;
            GridView1.DataBind();

            //db.sp_GetCandidateQuotas()
            //var r=(from q in db.CandidateQuotas
            //       join a in db.Archives 
            //       on new {q.AnnualEventID,q.CountyCode,q.SubjectID} equals a.AnnualEventID  into r1
            //             //where q.AnnualEventID == archive.AnnualEventID
            //             //&& q.SubjectID == archive.SubjectID
            //             //&& q.CountyCode == archive.CountyCode
            //             select q.Quota).Single();
            
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            IExpertJudgeBL ibl = new ExpertJudgeBL();
            Button3.Text = ibl.GetNewID();
            ExpertJudge expert = new ExpertJudge();
            expert.SerialNumber = Button3.Text;
            expert.SubjectID = 3;
            expert.AnnualEventID = "PY2012";
            expert.UserID = Guid.Parse("38F3DD5B-4A90-4A26-A544-A232793ABBA1");
            ibl.AddExpertJudge(expert);
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            ICandidateQuotaBL ibl = new CandidateQuotaBL();
            GridView1.DataSource = ibl.GetCandidateQuotas();
            GridView1.DataBind();
        }

        protected void btnGetArchiveScores_Click(object sender, EventArgs e)
        {
            IScoreBL ibl = new ScoreBL();
            GridView1.DataSource = ibl.GetArchiveScores(drpArchives.Text);
            GridView1.DataBind();
        }

        protected void btnExpScores_Click(object sender, EventArgs e)
        {
            IScoreBL ibl = new ScoreBL();
            GridView1.DataSource = ibl.GetExpertScores(drpExperts.Text);
            GridView1.DataBind();
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            IScoreBL ibl = new ScoreBL();
            List<Score> list = new List<Score>();
            list.Add(ibl.GetExpertArchiveScore(drpExperts.Text,drpArchives.Text));
            GridView1.DataSource = list;
            GridView1.DataBind();
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            ICandidateQuotaBL ibl = new CandidateQuotaBL();
            GridView1.DataSource = ibl.GetSubjectProgressReport(drpAnnualEvent.Text);
            GridView1.DataBind();

        }

        protected void btnSearchScores_Click(object sender, EventArgs e)
        {
            IScoreBL ibl = new ScoreBL();
            GridView1.DataSource = ibl.GetScores("PY2012",6, "pw20126","lw");
            GridView1.DataBind();
        }
    }
}